<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户管理</title>

<link rel="stylesheet"
	href="assets/bootstrap-table/bootstrap-table.css">
<link rel="stylesheet"
	href="assets/bootstrap-table/bootstrap-editable.css">
<script src="assets/bootstrap-table/jquery.min.js"></script>
<script src="assets/bootstrap-table/bootstrap.min.js"></script>
<script src="assets/bootstrap-table/bootstrap-table.js"></script>
<script src="assets/bootstrap-table/bootstrap-table-export.js"></script>
<script src="assets/bootstrap-table/tableExport.js"></script>
<script src="assets/bootstrap-table/bootstrap-table-editable.js"></script>
<script src="assets/bootstrap-table/bootstrap-editable.js"></script>
<script src="js/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="./bootstrap/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>

<link rel="stylesheet" type="text/css" href="date/css/pikaday.css"/>
<script type="text/javascript" src="date/js/pikaday.min.js"></script>

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/json2/20140204/json2.min.js"></script>
<![endif]-->
<style>
.ml10 {
	margin-left: 10px;
}

#operate-success {

	font-size: 16px;
	background-color: #8AC007;
	color: #FBFBFB;
	visibility: hidden
}
</style>
</head>
<body>
	<div class="container">
		<div class="page-header">
			<h1>公众号管理&nbsp;&nbsp;</h1>
		</div>
		<div style="text-align: center;">
			<span id="operate-success">设置成功</span>
		</div>



		<div id="toolbar" class="btn-group">
					<button id="plus" type="button" class="btn btn-default">
						<i class="glyphicon glyphicon-plus" title="添加微信公众号"></i><sapn>&nbsp;&nbsp;新增公众号</span>
					</button>
					<button id="edit" type="button" class="btn btn-default">
						<i class="glyphicon glyphicon-edit" title="编辑微信公众号"></i><sapn>&nbsp;&nbsp;编辑</span>
					</button>
					<button id="useHome" type="button" class="btn btn-default">
						<i class="glyphicon glyphicon-refresh" title="生成用户主页地址"></i><sapn>&nbsp;&nbsp;生成用户主页地址</span>
					</button>
  			 
			</div>
            
		    <div id="maintable">
			      <table id="table" data-id-field="foodId"data-striped="true"
					data-toolbar="#toolbar"
					data-search="true" data-show-refresh="true" data-show-toggle="true"
					data-pagination="true" data-show-columns="true" data-height="80%"
					data-click-to-select="true">
					<thead>
						<tr>
							<th data-field="state" data-checkbox="true"></th>
							<th data-align="left" data-field="campusId" >公众号ID</th>
							<th data-align="left" data-field="campusName" >公众号名称</th>
							<th data-align="left" data-field="customService" >电话号码</th>
							<th data-align="left" data-field="homePage" >用户主页地址</th>
							<th data-align="left" data-field="appId" data-visible="false" >AppID</th>
							<th data-align="left" data-field="appSecret" data-visible="false" >AppSecret</th>
						</tr>
					</thead>
				</table>
		</div>
	</div>
	
 <!-- 警告对话框 -->	
	<div class="modal fade" id="alertdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
          <div class="modal-content">
              <div class="modal-header blue">
                   <div >
                    	<strong id="alertchar" style="font-size:20px"></strong>
                   </div>
        
                   <div class="modal-footer">
			           <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			           <button type="button" id="commitFoodDataButton" class="btn btn-primary">确定</button>
	               </div> 
              </div>
         </div>
       </div>
   </div>
 
 <!-- 添加商品Modal start -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h3 class="modal-title" id="myModalLabel">新增公众号</h3>
				</div>
				<form id="dataCommit" class="form-horizontal" method="post"
					enctype="multipart/form-data" action="service/updateFoods.do">
					<div class="modal-body">
			          <div class="form-group none">
							<label for="campus_id_add_count" class="control-label col-md-4">校区ID</label>
							<div class="col-md-8">
								<input type="text" class="form-control" id="campusId2" name="campusId" readonly>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4" for="campusName2">公众号名称</label>
							   <div class="input-group  col-md-5">
								<input class="form-control" type="text" id="campusName2" name="campusName"
									placeholder="Name">
							   </div>							
						</div>
						<div class="form-group">
							<label class="control-label col-md-4" for="customService2">电话号码</label>
							<div class="input-group  col-md-5">
								<input class="form-control" type="text" id="customService2" name="customService"
									placeholder="customService">
							</div>							
						</div>
						<div class="form-group">
							<label class="control-label col-md-4" for="appId2">AppID</label>
							<div class="input-group  col-md-5">
								<input class="form-control" type="text" id="appId2" name="appId"
									placeholder="appId">
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4" for="appSecret2">AppSecret</label>
							<div class="input-group  col-md-5">
								<input class="form-control" type="text" id="appSecret2" name="appSecret"
									placeholder="appSecret">
							</div>
						</div>
                 </div>
                <div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button"
						class="btn btn-primary" onclick="commitFoodDataButton();">提交更改</button>
				</div>
		     </form>
		     <script type="text/javascript">
		     function commitFoodDataButton(){
				    //对表单的数据进行验证
				    var campusId=$("#campusId2").val();
		    	    var campusName=$("#campusName2").val();
				    var customService=$("#customService2").val();
				    var appId=$("#appId2").val();
				    var appSecret=$("#appSecret2").val();
				    
				    if(campusName==null||campusName==""){
				    	alert("公众号名称不能为空!");
				    	return;
				    }
				    
				    if(customService==null||customService==""){
				    	customService="-";
				    }
				    
				    if(appId==null||appId==""){
				    	appId="-";
				    }
				    
				    if(appSecret==null||appSecret==""){
				    	appSecret="-";
				    }
				        
				    $.post("weixinset/insertIntoCampus.do", {
                        campusId:campusId,
				    	campusName:campusName,
				    	customService:customService,
				    	appId:appId,
				    	appSecret:appSecret
					}, function(text) {
						if (text == -1 || text == 0) {
							$("#myModal").modal('hide');
							setSuccess("没有权限。");
						} else {
							$("#myModal").modal('hide');
							setSuccess("成功。");
							var url="weixinset/getCampusInfo.do";

					    	$(" #table").bootstrapTable('refresh',{
								url : url
							});
						}
					});
		     }
		     </script>
           </div>
      </div>
  </div>
 
 
 <script type="text/javascript">
 
	$("#table").bootstrapTable({
		url : "weixinset/getCampusInfo.do"
	 });
	
	$('#plus').click(function() {
		$("#myModal").modal('show');
		tag=0;
	});

	
	$('#edit').on('click',function() {
		var array = $('#table').bootstrapTable('getSelections');
		tag=1;

		if (array.length > 1) {
			$('#alertchar').text('编辑操作不能同时选中多条记录！');
			$('#commitFoodDataButton').hide();
			$('#alertdialog').modal("show");
		} else if (array.length == 0) {
			$('#alertchar').text('请先选中某条记录！');
			$('#commitFoodDataButton').hide();
			$('#alertdialog').modal("show");
		} else {
			$("#myModalLabel").text("编辑公众号");
			$("#myModal").modal('show');

			$("#campusId2").val(array[0].campusId);
			$("#campusName2").val(array[0].campusName);
			$("#customService2").val(array[0].customService);
			$("#appId2").val(array[0].appId);
			$("#appSecret2").val(array[0].appSecret);

			/*
			var status=document.getElementsByName("status")
			status[1-array[0].status].checked=true;
            */
		}
	});

	
	$('#useHome').on('click',function() {
		var array = $('#table').bootstrapTable('getSelections');
		tag=1;

		if (array.length > 1) {
			$('#alertchar').text('编辑操作不能同时选中多条记录！');
			$('#commitFoodDataButton').hide();
			$('#alertdialog').modal("show");
		} else if (array.length == 0) {
			$('#alertchar').text('请先选中某条记录！');
			$('#commitFoodDataButton').hide();
			$('#alertdialog').modal("show");
		} else {
			var campusId=array[0].campusId;
			$.post("templet/getHomePageTemplet.do", {
			         campusId:campusId
			    },function(text){

		        	 var json = eval('(' + text + ')');
						if (json.status == "success") {
							setSuccess("更新成功。");
							
							var url="weixinset/getCampusInfo.do";

					    	$(" #table").bootstrapTable('refresh',{
								url : url
							});
							
						}else{
							setSuccess(json.message);
						}
			});
			
		}
	});
 </script>  